package com.hhh.petadopt.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhh.petadopt.mapper.AdminMessageMapper;
import com.hhh.petadopt.pojo.LmessageVo;
import com.hhh.petadopt.pojo.LostMessage;
import com.hhh.petadopt.service.AdminMesageService;
import com.hhh.petadopt.utils.Page;
/**
 * 留言
 * @author 杜镇声声
 *
 */
@Service
public class AdminMesageServiceImpl implements AdminMesageService {
	@Autowired
	private AdminMessageMapper adminMessageMapper;

	//展示留言列表
	@Override
	public Page<LostMessage> selectPage(LmessageVo Vo) {
		//创建page对象
		Page<LostMessage> page = new Page<LostMessage>();
		//设置当前页显示的条数
		page.setSize(5);
		Vo.setSize(5);
		if(Vo != null) {
			//设置当前页
			if(null != Vo.getPage()) {
				Vo.setPage(Vo.getPage());
				//设置起始页
				Vo.setStartRow((Vo.getPage()-1)*Vo.getSize());
			}
			if(Vo.getLldate()!=null && !"".equals(Vo.getLldate().trim())) {
				Vo.setLldate(Vo.getLldate().trim());
			}
			//查询符合条件的总条数
			page.setTotal(adminMessageMapper.selectCount(Vo));
			//查询符合条件的当前页内容,进行封装
			List<LostMessage> selectPage = adminMessageMapper.selectPage(Vo);
			List<LostMessage> nList = new ArrayList<LostMessage>();
			for (LostMessage lostMessage : selectPage) {
				//将日期转换为yyyy-mm-dd格式
				lostMessage.setLdate(lostMessage.getLdate().substring(0, 10));
				nList.add(lostMessage);
			}
			page.setRows(nList);
		}
		
		return page;
	}

	//留言回显
	@Override
	public LostMessage selectMessageById(String id) {
		LostMessage selectMessageById = adminMessageMapper.selectMessageById(id);
		//将日期转换为yyyy-mm-dd格式
		selectMessageById.setLdate(selectMessageById.getLdate().substring(0, 10));
		return selectMessageById;
	}

	//禁言
	@Override
	public void updateShow(LostMessage lms) {
		adminMessageMapper.updateShow(lms);
		
	}

	//解除禁言
	@Override
	public void cancalKeepSay(String id) {
		adminMessageMapper.cancelkeepsay(id);
		
	}

	//删除单条留言
	@Override
	public void delMessageById(String id) {
		//执行操作
		adminMessageMapper.delMessageById(id);
		
	}

	//批量删除留言
	@Override
	public void delAllMessages(Integer[] ids) {
		adminMessageMapper.delAllMessagesByIds(ids);	
	}

}
